use std::{
    fs::File,
    io::{BufRead, BufReader},   
};
//type Result<T> = anyhow::Result<T>;

#[no_mangle]
fn file_pattern_filter(fname: &str) -> bool {
    if fname.ends_with(".log") {
        return true;
    }
    return false;
}

#[no_mangle]
fn proccess_file(fname: &str, args: &bytes::Bytes) -> String {
    println!("{:#?},  turn to json!", args);
    if let Ok(f) = File::open(&fname) {
        let reader = BufReader::new(f);
        let counts = reader.lines().count();
        let r = format!("{} = {}", fname, counts);
        return r;
    }
    return  format!("{} is not exist", fname)
}

#[no_mangle]
fn complete_notify(server: &str) {
    println!("hello, {}, I'm done", server);
}
